<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
		<view>
			<button @tap="change">{{ scene }}</button>
		</view>
		<view>
			<button @tap="shareText">分享文字</button>
			<button @tap="shareImage">分享图片</button>
			<button @tap="shareVideo">分享视频</button>
			<button @tap="shareHtml">分享网页</button>
			<button @tap="shareMiniProgram">分享小程序</button>
		</view>
		<view>
			<button @tap="login">微信登录</button>
		</view>
	</view>
</template>

<script>
	import { UniShareWeixinProviderImpl } from '@/uni_modules/uni-share-weixin';
	import { UniOAuthWeixinProviderImpl } from '@/uni_modules/uni-oauth-weixin'
	const shareImpl = new UniShareWeixinProviderImpl()
	const oauthImpl = new UniOAuthWeixinProviderImpl()
	export default {
		data() {
			return {
				title: 'Hello',
				scene: 'WXSceneSession'
			}
		},
		onLoad() {

		},
		methods: {
			change() {
				this.scene = this.scene === 'WXSceneSession' ? 'WXSceneTimeline' : 'WXSceneSession'
			},
			shareText() {
				shareImpl.share({
					provider: 'weixin',
					scene: this.scene,
					type: 1,
					title: 'uniapp开发',
					summary: 'hello world! 你好，世界',
					success: () => {
						uni.showModal({
							content: '分享成功'
						})
					},
					fail: (err) => {
						uni.showModal({
							content: JSON.stringify(err)
						})
					}
				})
			},
			shareImage() {
				shareImpl.share({
					provider: 'weixin',
					scene: this.scene,
					type: 2,
					title: 'uniapp开发',
					summary: 'hello world! 你好，世界',
					imageUrl: 'https://tb2.bdstatic.com/tb/static-common/img/search_logo_big_v2_d84d082.png',
					success: () => {
						uni.showModal({
							content: '分享成功'
						})
					},
					fail: (err) => {
						uni.showModal({
							content: JSON.stringify(err)
						})
					}
				})
			},
			shareVideo() {
				shareImpl.share({
					provider: 'weixin',
					scene: this.scene,
					type: 4,
					title: 'uniapp开发',
					summary: 'hello world! 你好，世界',
					imageUrl: 'https://tb2.bdstatic.com/tb/static-common/img/search_logo_big_v2_d84d082.png',
					mediaUrl: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4',
					success: () => {
						uni.showModal({
							content: '分享成功'
						})
					},
					fail: (err) => {
						uni.showModal({
							content: JSON.stringify(err)
						})
					}
				})
			},
			shareHtml() {
				shareImpl.share({
					provider: 'weixin',
					scene: this.scene,
					type: 0,
					title: 'uniapp开发',
					summary: 'hello world! 你好，世界',
					imageUrl: 'https://tb2.bdstatic.com/tb/static-common/img/search_logo_big_v2_d84d082.png',
					href: 'https://www.baidu.com',
					success: () => {
						uni.showModal({
							content: '分享成功'
						})
					},
					fail: (err) => {
						uni.showModal({
							content: JSON.stringify(err)
						})
					}
				})
			},
			shareMiniProgram() {
				shareImpl.share({
					provider: 'weixin',
					scene: this.scene,
					type: 5,
					title: 'uniapp开发',
					summary: 'hello world! 你好，世界',
					imageUrl: 'https://tb2.bdstatic.com/tb/static-common/img/search_logo_big_v2_d84d082.png',
					miniProgram: {
						id: 'xx_ssfsdf'
					},
					success: () => {
						uni.showModal({
							content: '分享成功'
						})
					},
					fail: (err) => {
						uni.showModal({
							content: JSON.stringify(err)
						})
					}
				})
			},
			login() {
				oauthImpl.login({
					privider: 'weixin',
					success: (res) => {
						uni.showModal({
							content: `success: ${JSON.stringify(res)}`
						})
					},
					fail: (err) => {
						uni.showModal({
							content: `fail: ${JSON.stringify(err)}`
						})
					}
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
